package edu.uoc.tds.pac4.client.ss3;

import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.Iterator;
import java.util.Vector;

import javax.swing.JPanel;
import javax.swing.JLabel;

import edu.uoc.tds.pac4.beans.EstIngressos;
import edu.uoc.tds.pac4.common.TDSLanguageUtils;

public class JPanelTotalsIngresosTotals extends JPanel {

	private static final long serialVersionUID = 1L;
	private JLabel jLabelTotals = null;
	private JLabel jLabelIngressos = null;
	private JLabel jLabelIngressosResultat = null;

	/**
	 * This is the default constructor
	 */
	public JPanelTotalsIngresosTotals() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		//Etiquetes
		GridBagConstraints gbcLabelTotals = new GridBagConstraints();
		gbcLabelTotals.gridx = 0;
		gbcLabelTotals.gridy = 0;
		gbcLabelTotals.gridheight = GridBagConstraints.RELATIVE;
		gbcLabelTotals.insets = new Insets(10, 10, 0, 50);
		jLabelTotals = new JLabel();
		jLabelTotals.setText(TDSLanguageUtils
				.getMessage("Client.PantallaPorcentatgeAssistencia.Totals"));
		jLabelTotals.setForeground(Color.RED);
		Font fuente = jLabelTotals.getFont();
		jLabelTotals.setFont(new Font(fuente.getFontName(), fuente.getStyle(), 30));
		
		
		
		GridBagConstraints gbcLabelIngressos = new GridBagConstraints();
		gbcLabelIngressos.gridx = 1;
		gbcLabelIngressos.gridy = 0;
		gbcLabelIngressos.insets = new Insets(0, 0, 0, 10);
		jLabelIngressos = new JLabel();
		gbcLabelIngressos.anchor = GridBagConstraints.LINE_END;
		jLabelIngressos.setText(TDSLanguageUtils
				.getMessage("Client.PantallaPorcentatgeAssistencia.Ingressos"));
		
		
		//Resultats
		GridBagConstraints gbcLabelIngressosResultat = new GridBagConstraints();
		gbcLabelIngressosResultat.gridx = 2;
		gbcLabelIngressosResultat.gridy = 0;
		jLabelIngressosResultat = new JLabel();
		gbcLabelIngressosResultat.anchor = GridBagConstraints.LINE_END;
		
		this.setLayout(new GridBagLayout());
		this.setName("jPanelTotals");
		this.add(jLabelTotals, gbcLabelTotals);
		this.add(jLabelIngressos, gbcLabelIngressos);
		this.add(jLabelIngressosResultat, gbcLabelIngressosResultat);

	}

	public void drawTotals(Vector<EstIngressos> currentLlistat)
	{
		Double ingressos = 0.0;
		// actualitza totals
		Iterator<EstIngressos> it = currentLlistat.iterator();
		while (it.hasNext()) {
			EstIngressos estIngressos = it.next();
			ingressos = ingressos + estIngressos.getIngres();
		}

		ingressos = Math.rint(ingressos*100)/100;
		jLabelIngressosResultat.setText(Double.toString(ingressos));

	}

}
